Skip to content

Conversation

FlowingSPDG
Copy link

Description of changes:
Add generics for HandlerFunc interface for type-safe StartHandlerFunc

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov-commenter
Copy link

Codecov Report

Merging #477 (627275f) into main (99a9a4b) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #477   +/-   ##
=======================================
  Coverage   71.18%   71.18%           
=======================================
  Files          21       21           
  Lines        1253     1253           
=======================================
  Hits          892      892           
  Misses        295      295           
  Partials       66       66           
Impacted Files Coverage Δ
lambda/entry_generic.go 100.00% <ø> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@@ -21,7 +21,7 @@ func TestStartHandlerFunc(t *testing.T) {
}

f := func(context.Context, any) (any, error) { return 1, nil }
StartHandlerFunc(f)
StartHandlerFunc[any, any](f)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a breaking change, as the go compiler isn't smart enough to infer the types when more than one variant is added to the interface. See prior discussion: #468 (comment)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thank you for considering this @bmoffatt !
I am still wondering if we can add this changes by adding another function (let's say StartTypedHandlerFunc for now)that accepts "any" type and it calls StartHandlerFunc[any, any](f).
There will be no type-safe though, but user does not need to specify types for StartHandlerFunc . instead, they may want to use new StartHandlerTypedFunc that supports generics with type parameter.

Sorry my English is not good enough to explain this, hope it works!

@bmoffatt bmoffatt added breaking change / v2 There is no plan for a v2 release! Alternative non-breaking approaches are strongly encouraged! wontfix labels Jan 5, 2023
@bmoffatt
Copy link
Collaborator

bmoffatt commented Jan 5, 2023

Not merging this one, the requirement to specify the in/out types breaks existing users.

@bmoffatt bmoffatt closed this Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change / v2 There is no plan for a v2 release! Alternative non-breaking approaches are strongly encouraged! wontfix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants